/* Copyright 2021 Kerim Yalcin
**
**   Licensed under the Apache License, Version 2.0 (the "License");
**   you may not use this file except in compliance with the License.
**   You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
**   Unless required by applicable law or agreed to in writing, software
**   distributed under the License is distributed on an "AS IS" BASIS,
**   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**   See the License for the specific language governing permissions and
**   limitations under the License.
*/

#ifndef AGX_DIRECTORY_HEADER
#define AGX_DIRECTORY_HEADER

#include <string>
#include <iostream>

#include <windows.h>

#include "../System/Error.hpp"

namespace Agx {

class Directory {
    private:
        Error mError;

        std::string mPath;
        std::string mPath_Absolute_determined;
        std::string mPath_Absolute_verified;
        std::string mPath_ofCurrentProcess;

        HANDLE mSearchHandle;
        WIN32_FIND_DATAA mFindData;
        bool mHas_found_noFile;
        bool mHas_found_noMoreFiles;

        std::string mDiskDesignator;
        std::string mPathName_onDiskDesignator;

        bool mIs_DefaultSecurityDescriptor_enabled;
        LPSECURITY_ATTRIBUTES mSecurityAttributes;
        PSECURITY_DESCRIPTOR mSecurityDescriptor;

        std::string mPath_ofTemplateDirectory;
        bool mIs_TemplateDirectory_enabled;

    private:
        void print_inSystemTimeFormat(const SYSTEMTIME& pTime) const;

    public:
        Directory();

        void set_Path(const std::string& pAbsolutePath);
        const std::string& get_Path();
        const std::string& get_Path_Absolute_determined();
        const std::string& get_Path_Absolute_verified();

        void set_Path_ofCurrentProcess(const std::string& pPath_ofCurrentProcess);
        const std::string& get_Path_ofCurrentProcess();

        void enable_DefaultSecurityDescriptor();
        void disable_DefaultSecurityDescriptor();
        void create_Directory();
        void remove_Directory();

        void find();
        void find_next();

        void find_print();
        void find_print_FileAttribute();
        void find_print_CreationTime();
        void find_print_LastAccessTime();
        void find_print_LastWriteTime();
        void find_print_FileSize();
        void find_print_FileName();

        const bool& has_found_noFile() const;
        const bool& has_found_noMoreFiles() const;

        void set_Path_ofTemplateDirectory(const std::string& pPathName);
        const std::string& get_Path_ofTemplateDirectory();
        void create_Directory_fromTemplate();

        void enable_SecurityAttributes_InheritHandle();
        void disable_SecurityAttributes_InheritHandle();

        void init_SecurityDescriptor();
        bool is_valid_SecurityDescriptor();       
};

}

#endif

/***** Documentation of Directory.hpp

End of Documentation *****/